//
//  findpasswordemailViewController.m
//  BAOASystem
//
//  Created by michael on 2018/2/7.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "OALoginViewController.h"
#import "findpasswordemailViewController.h"
#import "findpasswordtextViewController.h"
@interface findpasswordemailViewController ()

@end

@implementation findpasswordemailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
          self.navigationController.navigationBar.hidden = NO;

     NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 
[self.navigationController.navigationBar setTitleTextAttributes:attributes];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0a62ea"];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.title = NSLocalizedString(@"找回密码", nil);
    self.view.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
        [self initview];

}
- (void)initview{
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, KScreenWidth-20, 20)];
label.textColor = [UIColor colorWithHexString:@"484848"];
  NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];

label.text = [NSString stringWithFormat:@"%@%@",NSLocalizedString(@"您的登陆名:", nil),name];
label.backgroundColor = [UIColor clearColor];
[self.view addSubview:label];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, label.bottom+10, KScreenWidth-20, 20)];
label2.textColor = [UIColor colorWithHexString:@"484848"];
label2.text =NSLocalizedString(@"请输入与您登录名相匹配的邮箱", nil);
label2.backgroundColor = [UIColor clearColor];
[self.view addSubview:label2];
_textfield = [[UITextField alloc]initWithFrame:CGRectMake(10, label2.bottom+10, KScreenWidth-20, 40)];
     _textfield.delegate = self;

//  [_textfield addTarget:self action:@selector(endediting) forControlEvents:UIControlEventEditingDidEnd];

_textfield.backgroundColor = [UIColor whiteColor];
[self.view addSubview:_textfield];
 UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
      button2.frame = CGRectMake(10, _textfield.bottom+10, KScreenWidth-20, 40);
          button2.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];
//        [button2.layer setBorderColor:[UIColor blueColor].CGColor];
//    [button2.layer setBorderWidth:1];
// [button2.layer setMasksToBounds:YES];
    [button2 setTitle:NSLocalizedString(@"确认", nil) forState:UIControlStateNormal];
    button2.titleLabel.font = [UIFont systemFontOfSize: 14.0];
          [button2 setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
//        button2.layer.cornerRadius = button.height/2;
                [button2 addTarget:self action:@selector(action2) forControlEvents:UIControlEventTouchUpInside];

            [self.view addSubview:button2];
 UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];
      button3.frame = CGRectMake(10, button2.bottom+10, KScreenWidth-20, 40);
//          button3.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

button3.backgroundColor = [UIColor clearColor];
    [button3 setTitle:NSLocalizedString(@"跳转短信找回", nil) forState:UIControlStateNormal];
    button3.titleLabel.font = [UIFont systemFontOfSize: 14.0];
          [button3 setTitleColor:[UIColor colorWithHexString:@"0aa0f6"]forState:UIControlStateNormal];
//        button2.layer.cornerRadius = button.height/2;
                [button3 addTarget:self action:@selector(action3) forControlEvents:UIControlEventTouchUpInside];

            [self.view addSubview:button3];
_view1 = [[UIView alloc]initWithFrame:CGRectMake(KScreenWidth/2-125, 100, 250, 120)];
_view1.backgroundColor = [UIColor whiteColor];
UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, self.view1.width-20, 20)];
label3.textColor = [UIColor colorWithHexString:@"484848"];
    label3.font = [UIFont systemFontOfSize: 14.0];
label3.text =NSLocalizedString(@"重置密码邮件已发送至您的邮箱", nil);
label3.textAlignment = 1;
label3.backgroundColor = [UIColor clearColor];
[_view1 addSubview:label3];
UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(10, label3.bottom+10, self.view1.width-20, 20)];
    label4.font = [UIFont systemFontOfSize: 14.0];

label4.textColor = [UIColor colorWithHexString:@"484848"];
label4.text =NSLocalizedString(@"请注意查收!", nil);
label4.textAlignment = 1;
label4.backgroundColor = [UIColor clearColor];
[_view1 addSubview:label4];

 UIButton *button4 = [UIButton buttonWithType:UIButtonTypeCustom];
      button4.frame = CGRectMake(_view1.width/2-30, label4.bottom+10, 60, 30);
//          button3.backgroundColor = [UIColor colorWithHexString:@"0a62ea"];

button4.backgroundColor = [UIColor colorWithHexString:@"0aa0f6"];
    [button4 setTitle:NSLocalizedString(@"我知道了", nil) forState:UIControlStateNormal];
    button4.titleLabel.font = [UIFont systemFontOfSize: 13.0];
          [button4 setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
//        button2.layer.cornerRadius = button.height/2;
                [button4 addTarget:self action:@selector(action4) forControlEvents:UIControlEventTouchUpInside];

            [_view1 addSubview:button4];
[self.view addSubview:_view1];
_view1.hidden = YES;


}
- (void)action2{
NSString *oldstring=[_textfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

if ([oldstring isEqualToString:@""]|| oldstring.length == 0) {
     [self.view makeToast:NSLocalizedString(@"请输入与您登录名相匹配的邮箱", nil)];
}else{
NSString *emailstring=[_textfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];
     NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"password"];
     NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>administrator</userName><password>b628e2c3b78ef9bf269c489b35176e48</password><website>%@</website><language>%@</language><type>%@</type></header><body><user><username>%@</username><email>%@</email></user></body></message>",website,language,BAtype,name,oldstring];
    bodyStr= [bodyStr URLEncodedString];

 NSArray * array = @[@{@"arg0":bodyStr}];
     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bcheckEmail];

 [HttpTools requestWithURL:path arrays:array method:@"checkEmail" success:^(id JSON) {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"%@",JSON);
[self.view makeToast:JSON[@"msg"]];
if ([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"])
{
 
_type = @"ok";
[self action22];

}
    } failure:^(NSError *error) {
      [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];

}
}



- (void)action22{
NSString *oldstring=[_textfield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([oldstring isEqualToString:@""]|| oldstring.length == 0) {
     [self.view makeToast:NSLocalizedString(@"请输入与您登录名相匹配的邮箱", nil)];
}
else if (![_type isEqualToString:@"ok"]) {
 [self.view makeToast:NSLocalizedString(@"邮箱不存在", nil)];

}else{
NSString *name = [[NSUserDefaults standardUserDefaults] objectForKey:@"userName"];

      NSString *website = [[NSUserDefaults standardUserDefaults] objectForKey:@"website"];
   NSString *language = [[NSUserDefaults standardUserDefaults] objectForKey:@"language"];
 NSString *bodyStr = [NSString stringWithFormat:@"<?xml version='1.0' encoding='UTF-8'?><message><header><userName>administrator</userName><password>b628e2c3b78ef9bf269c489b35176e48</password><website>%@</website><language>%@</language><type>%@</type></header><body><user><username>%@</username><email>%@</email></user></body></message>",website,language,BAtype,name,oldstring];
     bodyStr= [bodyStr URLEncodedString];

 NSArray * array = @[@{@"arg0":bodyStr}];

     NSString * path = [NSString stringWithFormat:@"%@%@",BAip,bSendEmail];

 [HttpTools requestWithURL:path arrays:array method:@"SendEmail" success:^(id JSON) {
    [MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"%@",JSON);
[self.view makeToast:JSON[@"msg"]];
if ([[NSString stringWithFormat:@"%@",JSON[@"code"]]isEqualToString:@"200"])
{
 _view1.hidden = NO;
 }
    } failure:^(NSError *error) {
      [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];


}

}
- (void)action3{
//[_view1 removeFromSuperview];
findpasswordtextViewController *vc = [[findpasswordtextViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)action4{
UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

        OALoginViewController * loginVC = [storyBoard instantiateViewControllerWithIdentifier:@"LoginVC"];
        UINavigationController * navVC = [[UINavigationController alloc]initWithRootViewController:loginVC];
    self.view.window.rootViewController = navVC;
        loginVC.navigationController.navigationBar.hidden = YES;
//_view1.hidden = YES;
//[_view1 removeFromSuperview];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
